<template>
	<view class="search">
		<view class="search-add">
			<input confirm-type="add" @confirm="add()" v-model="searchInput" class="uni-input" focus placeholder="请输入研究方向" />
			<view class="add" @click.stop="add">添加</view>
		</view>
		<view class="search-tabs">
			<view class="tab" v-for="(item,index) in searchData" :key="index">
				<span>{{item}}</span>
				<uni-icons @click="cancleTab(index)" type="closeempty" color="#94BEFC" size="22" />
			</view>
		</view>
		<view class="person-info-bottom" :style="{'height':bottomHeight}">
			<view class="person-info-bottom-opt">
				<button @click="back">确定</button>
			</view>
		</view>
	</view>
</template>

<script>
	import uniIcons from '@/components/uni-icons/uni-icons.vue'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				searchInput: '',
				bottomHeight: '130rpx',
			}
		},
		onLoad(){
			let that = this
			uni.getSystemInfo({
				success: function(res) {
					console.log(res.model);
					if (res.model.indexOf('iPhone X') != -1 || res.model.indexOf('iPhone 11') != -1) { //XS,XR,XS MAX均可以适配,因为indexOf()会将包含'iPhone X'的字段都查出来
						that.bottomHeight = '205rpx'
					} else {
						that.bottomHeight = '130rpx'
					}
				}
			});
		},
		computed: {
			...mapState('userStore', ['searchData']),

		},
		methods: {
			...mapMutations('userStore', ['saveSearchData']),
			//添加
			add() {
				if (this.searchInput === '') {
					uni.showToast({
						title: '请输入研究方向',
						icon: 'none'
					})
					return
				}
				if (this.searchInput.length > 8) {
					uni.showToast({
						title: '研究方向不超过8个字',
						icon: 'none'
					})
					return
				}
				if (this.searchData.length >= 6) {
					uni.showToast({
						title: '研究方向不超过6个',
						icon: 'none'
					})
					return
				}
				this.searchData.push(this.searchInput);
				this.saveSearchData(this.searchData)
				this.searchInput = '';
				console.log(this.$store.state)
			},
			//删除当前tab
			cancleTab(index) {
				let arr = this.searchData.splice(index, 1);
				this.saveSearchData(this.searchData)
			},
			back(){
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.uni-input {
		padding-right: 150upx;
	}

	.search {
		border-top: 16upx solid #F5F5F5;
		box-sizing: border-box;
		padding: 34upx 40upx;

		.search-add {
			position: relative;

			input {
				line-height: 90upx;
				background: rgba(255, 255, 255, 1);
				border-radius: 4upx;
				border: 2upx solid rgba(221, 221, 221, 1);
				z-index: -1;
			}

			.add {
				position: absolute;
				right: 0;
				top: 50%;
				width: 200upx;
				height: 100upx;
				font-size: 30upx;
				line-height: 100upx;
				font-weight: 400;
				text-align: right;
				padding-right: 26upx;
				color: rgba(25, 109, 236, 1);
				transform: translateY(-50%);
				z-index: 999;
			}
		}

		.search-tabs {
			display: flex;
			flex-flow: wrap;
			margin-top: 44upx;

			.tab {
				height: 64upx;
				background: rgba(236, 245, 255, 1);
				border-radius: 4upx;
				border: 2upx solid rgba(217, 236, 255, 1);
				line-height: 64upx;
				padding: 0 6upx 0 20upx;
				margin-bottom: 20upx;
				font-size: 26upx;
				font-weight: 400;
				color: rgba(25, 109, 236, 1);
				margin-right: 20upx;

				span {
					display: inline-block;
					margin-right: 24upx;
				}
			}
		}
	}

	.person-info-bottom {
		box-shadow: 0px -4px 12px 0px rgba(0, 0, 0, 0.05);
		width: 100%;
		margin-top: 51upx;
		position: absolute;
		background: #fff;
		bottom: 0;
		left: 0;
		/* padding: 0 56upx; */
	}

	.person-info-bottom-opt>button {
		font-size: 30upx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(255, 255, 255, 1);
		height: 88upx;
		line-height: 88upx;
		background: linear-gradient(90deg, #55a5fd 0%, #2a7dfa 100%);
		border-radius: 12upx;
	}

	.person-info-radio {
		/* width: 26upx;
		height: 26upx; */
	}

	.person-info-bottom-opt {
		padding: 20upx 55upx;
	}

	.person-info-bottom-del {
		height: 98upx;
		background-color: #FFFFFF;
		font-size: 28upx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(243, 65, 66, 1);
		display: flex;
		align-items: center;
		padding-left: 71upx;
		margin-top: 16upx;
	}
</style>
